package com.hqq.rabbitmq.event;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;

/**
 * 模板登录事件发布者
 * @author huangqiqin
 * @date 2021/04/10 21:21
 **/
@Component
public class LoginEventPublisher {

    /**
     * 注入Spring事件发布器对象
     */
    @Autowired
    private ApplicationEventPublisher eventPublisher;

    /**
     * 发布登录事件
     */
    public void sendLoginEventMessage(){
        // 构造登录事件
        LoginEvent loginEvent = new LoginEvent(this, "张三", "zhangshan", "192.168.1.1");

        System.out.println(Thread.currentThread().getName() + " ==> 发布登录事件："+ loginEvent.toString());

        // 发布登录事件
        eventPublisher.publishEvent(loginEvent);
    }

}
